package com.mapapp.flutter_mapapp.widget;

import android.content.Context;
import android.os.CountDownTimer;
import android.widget.Button;

import com.mapapp.flutter_mapapp.R;

public class MyCountDownTimer extends CountDownTimer {

    private Button btn;
    private String endStrRid;
    private Context context;

    public MyCountDownTimer(Context context, long millisInFuture, long countDownInterval, Button btn, String endStrRid) {
        super(millisInFuture, countDownInterval);
        this.btn = btn;
        this.endStrRid = endStrRid;
        this.context = context;
    }

    @Override
    public void onFinish() {
        btn.setText(endStrRid);
        btn.setEnabled(true);
        btn.setTextColor(context.getResources().getColor(R.color.white));
    }

    @Override
    public void onTick(long millisUntilFinished) {
        btn.setEnabled(false);
        int time = (int) (Math.round((double) millisUntilFinished / 1000));
        btn.setText(String.valueOf(time) + "秒后重获");
        btn.setTextColor(context.getResources().getColor(R.color.white));
    }
}
